﻿using Syngine.Components;
using Syngine.Content;

namespace Syngine.Controls.Navigation
{
	/// <summary>
	/// 
	/// </summary>
	public class Menu : DrawableList<MenuItem>, IUpdate
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="Menu"/> class.
		/// </summary>
		/// <param name="commandHandler">The command handler.</param>
		public Menu(ICommandHandler commandHandler)
		{
			CommandHandler = commandHandler;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the command handler.
		/// </summary>
		/// <value>The command handler.</value>
		public ICommandHandler CommandHandler { get; set; }

		/// <summary>
		/// 
		/// </summary>
		public bool IsInitialized { get; private set; }

		#endregion

		#region Methods

		public static MenuItem Create(string text, params Asset[] assets)
		{
			return null;
		}

		/// <summary>
		/// 
		/// </summary>
		public virtual void Initialize()
		{
			IsInitialized = true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="context"></param>
		public virtual void Update(UpdateContext context)
		{
			for (var i = 0; i < Count; i++)
			{
				this[i].Update(context);
			}
		}

		/// <summary>
		/// Called when a child <see cref="MenuItem"/> is clicked.
		/// </summary>
		/// <param name="menuItem">The menu item.</param>
		public virtual void MenuItemClicked(MenuItem menuItem)
		{
			CommandHandler.Handle(menuItem.Command);
		}

		#endregion
	}
}